/**
 *  ward @ 2019
 *  harrydeep@wardyan.top
 */
package top.wardyan.base.action;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;

import top.wardyan.base.config.Const;
import top.wardyan.po.WButton;
import top.wardyan.po.WComposite;

/**
 * 
 * @author ward 2019年2月27日
 */
public abstract class BaseMenuComposite<T extends Composite> extends BaseComposite<T>{
	
	protected WComposite topMenu;
	protected WButton btnNew;
	protected WButton btnEdit;
	protected WButton btnDel;
	protected Integer margin = 10;
	

	/**
	 * @param parent
	 */
	public BaseMenuComposite(T parent) {
		super(parent);		
		this.init();
	}
	
	/** 在父类中已经设置颜色**/
	private void init() {
		this.topMenu = new WComposite(this, new Rectangle(0, 0, this.getSize().x, 50), Const.COLOR_GRAY);
		Point btnSize = this.genButtonSize();
		btnNew = new WButton(topMenu, SWT.NONE, new Rectangle(margin, margin / 2, btnSize.x, btnSize.y), "新增", this.genNewSelectionAdapter());
		btnEdit = new WButton(topMenu, SWT.NONE, new Rectangle(btnNew.getSize().x + btnNew.getLocation().x + margin, margin / 2, btnSize.x, btnSize.y), "编辑", this.genNewSelectionAdapter());
		btnDel = new WButton(topMenu, SWT.NONE, new Rectangle(btnEdit.getSize().x + btnEdit.getLocation().x + margin, margin / 2, btnSize.x, btnSize.y), "删除", this.genNewSelectionAdapter());
	}
	
	protected SelectionAdapter genNewSelectionAdapter() {
		return new SelectionAdapter() {};
	}
	protected SelectionAdapter genEditSelectionAdapter() {
		return new SelectionAdapter() {};
	}
	protected  SelectionAdapter genDelSelectionAdapter() {
		return new SelectionAdapter() {};
	}
	protected Point genButtonSize() {
		return new Point(60, this.topMenu.getSize().y - margin);
	}

}
